/**
 * fileName:  FruitNutritionReader.java
 * author:  huaimi
 * Company:  Cloudland Studio
 * Createdate:  2014-6-9 下午9:45:53
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-9          huaimi            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.store.read;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.cloudland.commercial.masterdata.bean.NutritionType;
import org.cloudland.commercial.masterdata.store.entity.FruitNutritionEntity;
import org.cloudland.jdbc.ibatis.masterdata.entity.NutritionRelationEntity;
import org.cloudland.jdbc.ibatis.masterdata.handler.NutritionRelationMapper;
import org.springframework.stereotype.Component;

 /**
 * 水果营养关系的与dao操作读实现类，提供对查询方法的实现
 * @ClassName  FruitNutritionReader
 * @author  huaimi
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
@Component
public class FruitNutritionReader 
{
	@Resource(name="nutritionRelationMapper")
	private NutritionRelationMapper nutritionRelationMapper;
	
	/**
	 * 
	 * 按水果编号查询水果对应营养关系集合
	 *
	 * @param fruitId 水果编号
	 * @return 水果对应的营养关系集合
	 */
	public List<FruitNutritionEntity> findFruitNutritionById(String fruitId)
	{
		List<NutritionRelationEntity> arrayNutrition = nutritionRelationMapper.findNutritionByFruitId(fruitId);
		if (null == arrayNutrition || arrayNutrition.size() <= 0) {
			return new ArrayList<FruitNutritionEntity>(0);
		}
		
		List<FruitNutritionEntity> result = new ArrayList<FruitNutritionEntity>(arrayNutrition.size());
		FruitNutritionEntity nutrition = null;
		NutritionType type = null;
		for (NutritionRelationEntity entity : arrayNutrition) {
			if (NutritionType.MINERAL.code().equals(entity.getNutritionType())) {
				type = NutritionType.MINERAL;
			} else if (NutritionType.NUTRIENT.code().equals(entity.getNutritionType())) {
				type = NutritionType.NUTRIENT;
			} else {
				type = NutritionType.VITAMI;
			}
			
			nutrition = new FruitNutritionEntity(entity.getFruitId(), entity.getNutritionId(), entity.getNutritionScalar(), entity.getCalculate(), entity.getSort(), type);
			result.add(nutrition);
		}
		
		return result;
	}
	
	public Integer countByFruitId(String fruitId)
	{
		Integer result = 0;
		//nutritionRelationMapper
		//TODO 添加查询方法
		return result;
	}
}
